home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d1
/
dosdev.arc
/
DOSDEV.ASM
next >
Wrap
Assembly Source File
|
1985-09-16
|
4KB
|
143 lines
; Listing 1 - DOSDEV.ASM
;** PC-DOS Device Driver (Generalized Skeleton for Character Devices)
;
; Bruce Bordner, 1985
;
;
CSEG SEGMENT PARA PUBLIC 'CODE'
;
XDV PROC FAR
ASSUME CS:CSEG,DS:CSEG,ES:CSEG
BEGIN:
START EQU $
; Header for DOS Device Drivers
NEXT_DEV DD -1 ; fake pointer to next device driver
ATTRIBUTE DW 0C000H ;character device with IOCTL capability
STRATEGY DW XDV_STRAT ;pointer to function which queues request header
FUNC_CALL DW XDV_FUNC ;pointer to operating functions switch
DEV_NAME DB 'XDV ' ;8-byte device name field
;
; Pointer to function request from DOS
RH_OFF DW ?
RH_SEG DW ?
;
; Function Address Table for DOS Requests
FUNTAB LABEL BYTE
DW INIT ; initialize device
DW MEDIA_CHECK ; do a media check (block dev only)
DW BUILD_BPB ; build BPB " " "
DW IOCTL_IN ; IOCTL input
DW INPUT ; normal input (read device)
DW ND_INPUT ; non-destructive input no wait
DW IN_STAT ; report input status
DW IN_FLUSH ; flush input
DW OUTPUT ; output (write to device)
DW OUT_VERIFY ; output with verify
DW OUT_STAT ; report output status
DW OUT_FLUSH ; flush output
DW IOCTL_OUT ; IOCTL output
;
;
; Internal Data
;
; *end local data
;
;
;
; Device Strategy - set pointer to request header from DOS
XDV_STRAT: MOV CS:RH_SEG,ES
MOV CS:RH_OFF,BX
RET
;
; Device Interrupt Handler
XDV_FUNC: ;preserve machine state
PUSHF
CLD
PUSH DS
PUSH ES
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
PUSH SI
; Set DS to CS value
PUSH CS
POP DS
; Load ES and BX with RH_SEG and RH_OFF
LES BX,DWORD PTR CS:RH_OFF
; Branch to correct function in FUNTAB based on function code from DOS
MOV AL,ES:[BX+2] ; get function code byte
XOR AH,AH
SHL AL,1 ; make it into offset into FUNTAB
LEA DI,FUNTAB ; get address of FUNTAB base
ADD DI,AX
JMP WORD PTR[DI] ; jump to function code
;
;
;
; Device Initialization
INIT: MOV DX,OFFSET LASTWORD ;end offset of XDV
MOV ES:[BX+14],DX
MOV ES:[BX+16],CS ; and segment into request hdr
MOV WORD PTR ES:[BX+3],0100H ;set status word to DONE, NOERROR
JMP EXIT
;
;
; Functions not supported:
;
MEDIA_CHECK:
BUILD_BPB:
IOCTL_IN:
ND_INPUT:
IN_STAT:
IN_FLUSH:
OUT_VERIFY:
OUT_STAT:
OUT_FLUSH:
IOCTL_OUT:
MOV ES:WORD PTR [BX+3],0100H ; set status DONE, NOERROR
JMP EXIT
;************************************************************
; ES:[BX]+14 = offset of buffer in calling program
; ES:[BX]+16 = segment of buffer
; ES:[BX]+18 = number of bytes to transfer in this call
; (NOTE: DOS 2 requests one byte per call)
;
INPUT:
;
MOV WORD PTR ES:[BX+3],0100H ; set DONE, NOERROR
JMP EXIT
;*************************************************************
; ES:[BX]+14 = offset of buffer in calling program
; ES:[BX]+16 = segment of buffer
; ES:[BX]+18 = number of bytes to transfer in this call
; (NOTE: DOS 2 requests one byte per call)
;
OUTPUT:
MOV WORD PTR ES:[BX+3],0100H ; set DONE, NOERROR
JMP EXIT
;*********************************************************
;
; Restore registers and exit
EXIT: POP SI
POP DI
POP DX
POP CX
POP BX
POP AX
POP ES
POP DS
POPF
RET
;
LASTWORD EQU $ ;end of XDV - used for terminate & stay resident
XDV ENDP
CSEG ENDS
END BEGIN
POPF
RET
;
LASTWORD EQU $ ;end of XDV - used for terminate & stay resident